#include <stdio.h>
#include <unistd.h>

int main()
{
    int fd[2];
    pipe(fd);
    pid_t pid = fork();
    if(pid<0)
    {
        perror("fork\n");
        return 0;
    }
    else if(pid == 0)
    {
        //child
        close(fd[1]);
        printf("child f[0]:%d\n",fd[0]);
        char* buf[1024]={0};
        read(fd[0],buf,sizeof(buf)-1);
        printf("child read:%s\n",buf);
    }
    else 
    {
        close(fd[0]);
        printf("father f[0]:%d\n",fd[0]);
        write(fd[1],"haha",4);
    }
    while(1)
    {
        sleep(1);
    }
    return 0;
}
